#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    //1.先获取两个输入框中的时间
    QDateTime timeOld = ui->dateTimeEdit->dateTime();
    QDateTime timeNew = ui->dateTimeEdit_2->dateTime();

    //2.计算日期差值
    //int days = timeOld.daysTo(timeNew);
    int seconds = timeOld.secsTo(timeNew);
    int days = (seconds / 3600) / 24;

    //3.把秒数转换为小时
    int hours = (seconds / 3600) % 24;

    ui->label->setText("时间差为:" + QString::number(days) + "天" + QString::number(hours) + "小时");


}

